package com.hc.demo_thy;

import org.springframework.ui.Model;
import com.hc.demo_thy.domain.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class HelloController {

    //ThymeleafProperties thymeleafProperties;
    // RedisProperties redisProperties;
    @RequestMapping("/hello4")
    public ModelAndView hello4(){
        List<Person> personList=new ArrayList<>();

        Person person=new Person();
        person.setId(100011);
        person.setUsername("牢大");
        person.setBirthday(new Date());

        personList.add(person);

        Person person2=new Person();
        person2.setId(100);
        person2.setUsername("牢二");
        person2.setBirthday(new Date());

        personList.add(person2);

        return new ModelAndView("test","list",personList);
    }
    //接口方法：处理用户的请求
    //  localhost:9090/hello
    @RequestMapping("/hello")
    public ModelAndView hello(Model model){

        Person person=new Person();
        person.setId(100011);
        person.setUsername("牢大");
        person.setBirthday(new Date());

        model.addAttribute("per",person);
        model.addAttribute("username","微风");
        //发生了什么？SpringMVC的一个场景：ViewHandler解析器解析 hello,拼凑长名字： /templates/hello.html
        return new ModelAndView("hello"); // hello是页面名字，是短名字，没有前缀没有后缀

    }

    //接口方法：处理用户的请求
    //  localhost:8080/hello
    @RequestMapping("/hello2")
    public ModelAndView hello2(){
        String username="张三";
        return new ModelAndView("hello","username",username);
    }

    //接口方法：处理用户的请求
    //  localhost:8080/hello
    @RequestMapping("/hello3")
    public ModelAndView hello3(){

        //模拟一个对象，传给页面
        Person person=new Person();
        person.setId(100);
        person.setUsername("小红花");
        person.setBirthday(new Date());

        return new ModelAndView("hello","per",person);
    }
}

